<!doctype html>
<html lang="zh-CN">
<head>  
    <title>接口文档</title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.2.2/jquery.form.min.js" integrity="sha384-FzT3vTVGXqf7wRfy8k4BiyzvbNfeYjK+frTVqZeNDFl8woCbF0CYG6g2fMEFFo/i" crossorigin="anonymous"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
    <link href="https://cdn.bootcss.com/toastr.js/2.1.4/toastr.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/toastr.js/2.1.4/toastr.min.js"></script>
    
    
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css">

    <!-- Latest compiled and minified JavaScript -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script>

    <!-- (Optional) Latest compiled and minified JavaScript translation files -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/i18n/defaults-*.min.js"></script>
</head>
<body>
    <div class="container">
        ddd
    </div>
    
    <script>
        toastr.options = {
            closeButton: true,
            debug: true,
            progressBar: true,
            positionClass: "toast-top-center",
            onclick: null,
            showDuration: "300",
            hideDuration: "1000",
            timeOut: "2000",
            extendedTimeOut: "1000",
            showEasing: "swing",
            hideEasing: "linear",
            showMethod: "fadeIn",
            hideMethod: "fadeOut"
        };
        var locked=false;
        //toastr.warning("请输入所有数据");      
        //toastr.success('提交数据成功');
        $(document).ready(function() { 

            $("#myForm").submit(function(){
                if(!locked){
                    locked=true;
                    $(this).ajaxSubmit({
                        //target:'#output1',  //把服务器返回内容放入id为output1的元素中
                        beforeSubmit:function(res){  
                            var hasProduct=false;
                            for(var index in res){
                                if(res[index]['name']=="customer"&&res[index]['value']==""){
                                    toastr.warning("请输入客户名称！");
                                    $("input[name='customer']").focus();
                                    locked=false;
                                    return false;
                                }
                                
                                if(res[index]['name']=="product[]"){
                                    hasProduct=true;
                                }  
                            }
                            
                            
                            if(!hasProduct){
                                toastr.warning("请选择产品！");
                                $("#product").focus();
                                locked=false;
                                return false;
                            }
                        }, 
                        success:function(){
                            toastr.success('提交数据成功');
                            setTimeout(function(){window.location.href="{:url('index/index')}";}, 3000);
                        },  
                        dateType:"json",
                    });
                }
                return false;
            });
        });  
       
    </script>
    
</body>
</html>
